package com.yanqu.road.server.manger.cricket.skillhandler.attround.handler;

import com.yanqu.road.entity.cricket.helper.AddHpResult;
import com.yanqu.road.entity.enums.eSkillType;
import com.yanqu.road.pb.cricket.CricketProto;
import com.yanqu.road.server.gameplayer.module.cricket.battle.CricketGame;
import com.yanqu.road.server.gameplayer.module.cricket.model.BattleData;
import com.yanqu.road.server.gameplayer.module.cricket.model.SkillData;
import com.yanqu.road.server.manger.cricket.skillhandler.attround.CricketSkillAttRoundStrategy;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class CricketSkill400Strategy implements CricketSkillAttRoundStrategy {

    /**
     * 所有冲夹替换成青龙偃月刀，每次冲夹时提升关羽自身{0}的攻击力，加成可叠加。
     * @param cricketGame 本局对局对象
     * @param skillData 触发的技能
     * @param baseAttSkill 基础攻击技能
     * @param baseAttReHpResult 基础攻击结果对象
     * @param action 我方
     * @param target 对方
     * @param attackRoundBuilder 返回PB结构体
     * @param battleFrameId 本次攻击的FrameId
     * @return true：死亡，退出技能处理，false：继续技能处理
     */
    @Override
    public boolean skillHandle(CricketGame cricketGame, SkillData skillData, SkillData baseAttSkill, AddHpResult baseAttReHpResult, BattleData action, BattleData target, CricketProto.CricketAttackRound.Builder attackRoundBuilder, long battleFrameId) {

        if (baseAttSkill.getSkillEffect().getSkillType() == eSkillType.CricketBattleSkill137.getValue() && baseAttSkill.getSkillEffect().getP4() == 2) {//1快夹2冲夹3举摔
            skillData.effectAmountInc();
            long addAttack = BigDecimal.valueOf(action.getBaseAtk()).multiply(BigDecimal.valueOf(skillData.getSkillEffect().getP1())).divide(BigDecimal.valueOf(1000), 8, RoundingMode.DOWN).longValue();
            CricketProto.CricketBattleFrame.Builder newBattleFrameBuilder = cricketGame.newBattleFrameBuilder();
            newBattleFrameBuilder.setActionUserId(action.getUserId());
            newBattleFrameBuilder.setTargetUserId(action.getUserId());
            newBattleFrameBuilder.setSkillId(skillData.getSkillId());
            action.setAddAttack(action.getAddAttack() + addAttack);
            newBattleFrameBuilder.setAddAttack(addAttack);
            cricketGame.fillRemainHp(newBattleFrameBuilder);
            attackRoundBuilder.addStartRound(newBattleFrameBuilder);
        }
        return false;
    }
}
